<?php
require '../database.inc.php';
require '../MessageRepository.php';
require '../UserRepository.php';

header('Content-type: application/json');
$username = $_POST['username'];
$messageId = $_POST['messageId'];
$text = $_POST['text'];
$userRepository = new UserRepository();
$messageRepository = new MessageRepository();
$commentId = $messageRepository->addCommentToMessage($db, $messageId, $userRepository->getUsersID($db, $username), $text);
$data = array('commentId' => $commentId, 'username' => $username, 'messageId' => $messageId, 'text' => $text);
$json = json_encode($data);
echo $json;
?>
